<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>{$Think.config.site.title} - 用户管理</title>
    <meta name="keywords" content="{$Think.config.site.keywords}">
    <meta name="description" content="{$Think.config.site.description}">

    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.min.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.min.css?v=4.0.0" rel="stylesheet">
    <link href="{$Think.config.site.common_resource_url}js/chosen/chosen.css" rel="stylesheet" type="text/css"/>
</head>
<style type="text/css">
.chosen-select{
    width: 100%;
}
</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-7">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>{$title}</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                      	</div>
                    </div>
                    <div class="ibox-content">
                        <form method="get" class="form-horizontal">
                        <input type="hidden" name="id" value="{$list['id'] ?? ''}" />
                            <div class="form-group">
                                <label class="col-sm-2 control-label">昵称</label>
                                <div class="col-sm-10">
                                    <input id="username" name="username" class="form-control" readonly type="text" value="{$list['nickname'] ?? ''}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">用户电话号码</label>
                                <div class="col-sm-10">
                                    <input id="phone" name="phone" class="form-control" type="text" value="{$list['phone'] ?? ''}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商户名称</label>
                                <div class="col-sm-10">
                                    <input id="shop_name" name="shop_name" class="form-control" type="text" value="{$list['shop_name'] ?? ''}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商户负责人</label>
                                <div class="col-sm-10">
                                    <input id="shop_owner" name="shop_owner" class="form-control" type="text" value="{$list['shop_owner'] ?? ''}">
                                </div>
                            </div>  
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商户地址</label>
                                <div class="col-sm-10">
                                    <input id="shop_address" name="shop_address" class="form-control" type="text" value="{$list['shop_address'] ?? ''}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商户类型</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="sc_id" id="sc_id">
                                        <option value="0">无</option>
                                        {volist name="cate" id="vo"}
                                        <option value="{$vo.sc_id}" {if($list['sc_id']==$vo['sc_id'])} selected="selected" {/if}>{$vo.sc_name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
     
                                    <input type="submit" class="btn btn-primary" value="提交">
                           
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
    <script src="{$Think.config.site.resource_url}js/content.min.js?v=1.0.0"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/validate/jquery.validate.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/validate/messages_zh.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
    <script type="text/javascript" src="{$Think.config.site.common_resource_url}js/chosen/chosen.jquery.js"></script>
</body>

</html>
<script>
$(document).ready(function(){
    $(".chs").chosen({no_results_text: "没有找到："});
	$("form").validate({
	  debug:true,
	  submitHandler:function(form){
            save();   
      },    
	  rules: {
		phone: {
		  number: true,
		  minlength: 6,
		}
	  },
	  messages: {
		username: {
		  required: '用户名必须填写',
		  minlength: '用户名不能少于4位',
		},
		phone: {
		  number: '电话号码只能包含数字',
		  minlength: '电话号码不能少于6位',
		}
	  }
	});

	function save(){
		var fomrData = $("form").serialize();
		$.ajax({
			type : 'POST',
			url : '{:url("edit")}',
			dataType : 'json',
			data : fomrData,
			success : function(result) {
                if(1 === result.code){
                    var data = {
                        username : $("#username").val(),
                        phone : $("#phone").val(),
                        shop_name : $("#shop_name").val(),
                        shop_owner : $("#shop_owner").val(),
                        shop_address : $("#shop_address").val(),
                        sc_name : $("#sc_id option:selected").text()
                    }
                    parent.editSuccess(data);
                }else{
                    //修改失败
                    layer.msg(result.msg, {icon: 5});
                }
                console.log(result);
			},
			error : function(){
				layer.msg('服务器错误！请稍后重试', {icon: 2});
			}
		})
	};
})
</script>